home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
OLE2BOOK.ZIP
/
CHAP08.ZIP
/
CHAP08
/
PATRON
/
PAGEWIN.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-17
|
23KB
|
832 lines
/*
* PAGEWIN.CPP
* Modifications for Chapter 8
*
* Window procedure for the Pages window and support functions. This
* window manages its own scrollbars and viewport and provides
* printing capabilities as well. The public CPages::Print lives here.
*
* Copyright (c)1993 Microsoft Corporation, All Rights Reserved
*
* Kraig Brockschmidt, Software Design Engineer
* Microsoft Systems Developer Relations
*
* Internet : kraigb@microsoft.com
* Compuserve: >INTERNET:kraigb@microsoft.com
*/
#include "patron.h"
extern HWND g_hDlgPrint;
extern BOOL g_fCancelPrint;
/*
* PagesWndProc
*
* Purpose:
* Window procedure for the Pages window.
*/
LRESULT __export FAR PASCAL PagesWndProc(HWND hWnd, UINT iMsg
, WPARAM wParam, LPARAM lParam)
{
LPCPages ppg;
PAINTSTRUCT ps;
HDC hDC;
int iPos, iTmp;
int iMin, iMax;
UINT idScroll;
BOOL fDirty=FALSE;
ppg=(LPCPages)GetWindowLong(hWnd, PAGEWL_STRUCTURE);
switch (iMsg)
{
case WM_CREATE:
ppg=(LPCPages)((LPCREATESTRUCT)lParam)->lpCreateParams;
SetWindowLong(hWnd, PAGEWL_STRUCTURE, (LONG)ppg);
ppg->m_hWnd=hWnd;
break;
case WM_PAINT:
//CHAPTER8MOD
/*
* If there is currently a drag-rectangle showing, then
* remove it before painting. This insures that painting
* doesn't blast part of that rectangle away such that when
* we draw it next, garbage is left around.
*/
if (ppg->m_fDragRectShown)
ppg->DrawDropTargetRect(NULL, NULL);
//End CHAPTER8MOD
hDC=BeginPaint(hWnd, &ps);
//Draw only if we have a page to show.
if (0!=ppg->m_cPages)
ppg->Draw(hDC, FALSE, FALSE);
EndPaint(hWnd, &ps);
//CHAPTER8MOD
//Turn the rectangle back on, if necessary.
if (ppg->m_fDragRectShown)
ppg->DrawDropTargetRect(NULL, NULL);
//End CHAPTER8MOD
break;
case WM_HSCROLL:
case WM_VSCROLL:
idScroll=(WM_HSCROLL==iMsg) ? SB_HORZ : SB_VERT;
iPos=GetScrollPos(hWnd, idScroll);
iTmp=iPos;
GetScrollRange(hWnd, idScroll, &iMin, &iMax);
switch (wParam)
{
case SB_LINEUP: iPos -= 20; break;
case SB_PAGEUP: iPos -=100; break;
case SB_LINEDOWN: iPos += 20; break;
case SB_PAGEDOWN: iPos +=100; break;
case SB_THUMBPOSITION:
iPos=ScrollThumbPosition(wParam, lParam);
break;
//We don't want scrolling on this message.
case SB_THUMBTRACK:
return 0L;
}
iPos=max(iMin, min(iPos, iMax));
if (iPos!=iTmp)
{
//Set the new position and scroll the window as necessary.
SetScrollPos(hWnd, idScroll, iPos, TRUE);
if (SB_HORZ==idScroll)
{
ppg->m_xPos=iPos;
ScrollWindow(hWnd, iTmp-iPos, 0, NULL, NULL);
}
else
{
ppg->m_yPos=iPos;
ScrollWindow(hWnd, 0, iTmp-iPos, NULL, NULL);
}
}
break;
case WM_LBUTTONDOWN:
if (NULL==ppg->m_pPageCur)
break;
fDirty=ppg->m_pPageCur->OnLeftDown(wParam
, LOWORD(lParam), HIWORD(lParam));
break;
case WM_LBUTTONUP:
if (NULL==ppg->m_pPageCur)
break;
fDirty=ppg->m_pPageCur->OnLeftUp(wParam
, LOWORD(lParam), HIWORD(lParam));
break;
case WM_LBUTTONDBLCLK:
if (NULL==ppg->m_pPageCur)
break;
fDirty=ppg->m_pPageCur->OnLeftDoubleClick(wParam, LOWORD(lParam)
, HIWORD(lParam));
break;
case WM_MOUSEMOVE:
if (NULL==ppg->m_pPageCur)
break;
ppg->m_pPageCur->OnMouseMove(wParam, LOWORD(lParam)
, HIWORD(lParam));
break;
case WM_NCHITTEST:
if (NULL!=ppg->m_pPageCur)
{
//This just saves information in the page for OnSetCursor
ppg->m_pPageCur->OnNCHitTest(LOWORD(lParam)
, HIWORD(lParam));
}
return DefWindowProc(hWnd, iMsg, wParam, lParam);
case WM_SETCURSOR:
if (NULL!=ppg->m_pPageCur)
{
if (ppg->m_pPageCur->OnSetCursor(LOWORD(lParam)))
break;
}
return DefWindowProc(hWnd, iMsg, wParam, lParam);
default:
return DefWindowProc(hWnd, iMsg, wParam, lParam);
}
ppg->m_fDirty |= fDirty;
return 0L;
}
/*
* RectConvertMappings
*
* Purpose:
* Converts the contents of a rectangle from device to logical
* coordinates where the hDC defines the logical coordinates.
*
* Parameters:
* pRect LPRECT containing the rectangle to convert.
* hDC HDC describing the logical coordinate system.
* if NULL, uses a screen DC in MM_LOMETRIC.
* fToDevice BOOL TRUE to convert from uConv to device,
* FALSE to convert device to uConv.
*
* Return Value:
* None
*/
void RectConvertMappings(LPRECT pRect, HDC hDC, BOOL fToDevice)
{
POINT rgpt[2];
BOOL fSysDC=FALSE;
if (NULL==pRect)
return;
rgpt[0].x=pRect->left;
rgpt[0].y=pRect->top;
rgpt[1].x=pRect->right;
rgpt[1].y=pRect->bottom;
if (NULL==hDC)
{
hDC=GetDC(NULL);
SetMapMode(hDC, MM_LOMETRIC);
fSysDC=TRUE;
}
if (fToDevice)
LPtoDP(hDC, rgpt, 2);
else
DPtoLP(hDC, rgpt, 2);
if (fSysDC)
ReleaseDC(NULL, hDC);
pRect->left=rgpt[0].x;
pRect->top=rgpt[0].y;
pRect->right=rgpt[1].x;
pRect->bottom=rgpt[1].y;
return;
}
/*
* CPages::Draw
*
* Purpose:
* Paints the current page in the pages window.
*
* Parameters:
* hDC HDC to draw on, could be a metafile or printer DC or
* any other type of DC.
* fNoColor BOOL indicating if we should use screen colors or
* printer colos (B&W). Objects are printed as-is, however.
* This is TRUE for printer DCs or print preview.
* fPrinter BOOL indicating if this is a printer DC in which case
* we eliminate some of the fancy drawing, like shadows on
* the page and so forth.
*
* Return Value:
* None
*/
void CPages::Draw(HDC hDC, BOOL fNoColor, BOOL fPrinter)
{
RECT rc, rcT;
UINT uMM;
HPEN hPen;
HBRUSH hBrush;
HGDIOBJ hObj1, hObj2;
COLORREF cr;
char szTemp[20];
UINT cch;
DWORD dwExt;
LPPAGE pPage;
RECT rcPos;
//Make sure the DC is in LOMETRIC
uMM=SetMapMode(hDC, MM_LOMETRIC);
if (!fPrinter)
{
/*
* We maintain a 6mm border around the page on the screen besides
* 12.7mm margins. We also have to account for the scroll position
* with m_*Pos which are in pixels so we have to convert them.
*/
SetRect(&rcPos, m_xPos, m_yPos, 0, 0);
RectConvertMappings(&rcPos, hDC, FALSE);
rc.left = LOMETRIC_BORDER-rcPos.left;